import { Controller, Get, Post, Query, Body } from '@nestjs/common';
import { ApiOperation } from '@nestjs/swagger';
import { CityService } from './city.service';
import { CreateCityDto } from './dto/create-city.dto';
import { CityEntity } from './entities/city.entity';

@Controller('city')
export class CityController {
  constructor(private cityService: CityService) {}

  @ApiOperation({ summary: '查询所有城市' })
  @Get()
  findAll(): Promise<CityEntity[]> {
    return this.cityService.findAll();
  }

  @ApiOperation({ summary: '根据关键字搜索城市' })
  @Get('search')
  search(@Query('q') q: string): Promise<CityEntity[]> {
    return this.cityService.searchByName(q);
  }

  @ApiOperation({ summary: '创建城市' })
  @Post()
  create(@Body() dto: CreateCityDto): Promise<CityEntity> {
    return this.cityService.create(dto);
  }
}
